package com.school.graduation.goods.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

import com.school.graduation.util.NetWorkUtil;

public class InternetConnectStatusReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        NetworkInfo activeNetwork = ((ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE)).getActiveNetworkInfo();

        if (!ConnectivityManager.CONNECTIVITY_ACTION.equals(intent.getAction())
                ||activeNetwork == null
                || !activeNetwork.isConnected()) { // connected to the internet
            NetWorkUtil.netWorkConnected = false;
            return;
        }
        if (activeNetwork.getType() == ConnectivityManager.TYPE_WIFI
                ||activeNetwork.getType() == ConnectivityManager.TYPE_MOBILE) {
            //LogUtil.e(TAG, "当前WiFi连接可用 ");
            NetWorkUtil.netWorkConnected = true;
        }
    }
}
